<template>
  <view class="user-card">
    <!-- 头像区域 -->
    <view class="avatar-section">
      <image 
        :src="avatarUrl" 
        class="avatar"
        mode="aspectFill"
      />
      <view class="avatar-border"></view>
    </view>
    
    <!-- 用户信息区域 -->
    <view class="user-info">
      <text class="nickname">{{ nickname }}</text>
      <text class="register-time">注册时间: {{ formatRegisterTime }}</text>
    </view>
    
    <!-- 装饰元素 -->
    <view class="card-decoration">
      <view class="decoration-dot"></view>
      <view class="decoration-dot"></view>
      <view class="decoration-dot"></view>
    </view>
  </view>
</template>

<script setup>
import { computed } from 'vue'

// 定义组件接收的props
const props = defineProps({
  avatarUrl: {
    type: String,
    default: '/static/logo.png' // 默认头像
  },
  nickname: {
    type: String,
    required: true
  },
  registerTime: {
    type: String,
    required: true
  }
})

// 格式化注册时间
const formatRegisterTime = computed(() => {
  if (!props.registerTime) return '未知'
  
  try {
    const date = new Date(props.registerTime)
    const year = date.getFullYear()
    const month = String(date.getMonth() + 1).padStart(2, '0')
    const day = String(date.getDate()).padStart(2, '0')
    return `${year}-${month}-${day}`
  } catch (error) {
    return props.registerTime
  }
})

// 头像加载失败处理
const onAvatarError = () => {
}
</script>

<style scoped lang="scss">
.user-card {
  position: relative;
  background: linear-gradient(135deg, #56ab2f 0%, #a8e6cf 100%);
  border-radius: 20rpx;
  padding: 40rpx 30rpx;
  margin: 20rpx;
  box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  overflow: hidden;
  
  // 点击效果
  &:active {
    transform: scale(0.98);
    transition: transform 0.1s ease;
  }
}

// 头像区域
.avatar-section {
  position: relative;
  margin-right: 30rpx;
  
  .avatar {
    width: 100rpx;
    height: 100rpx;
    border-radius: 50%;
    border: 4rpx solid #fff;
    box-shadow: 0 4rpx 15rpx rgba(0, 0, 0, 0.2);
  }
  
  .avatar-border {
    position: absolute;
    top: -8rpx;
    left: -8rpx;
    width: 116rpx;
    height: 116rpx;
    border-radius: 50%;
    border: 2rpx solid rgba(255, 255, 255, 0.3);
  }
}

// 用户信息区域
.user-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  
  .nickname {
    font-size: 32rpx;
    font-weight: bold;
    color: #fff;
    margin-bottom: 10rpx;
    text-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.2);
  }
  
  .register-time {
    font-size: 24rpx;
    color: rgba(255, 255, 255, 0.8);
    font-weight: 300;
  }
}

// 装饰元素
.card-decoration {
  position: absolute;
  top: 20rpx;
  right: 30rpx;
  display: flex;
  gap: 8rpx;
  
  .decoration-dot {
    width: 8rpx;
    height: 8rpx;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.6);
    
    &:nth-child(2) {
      background-color: rgba(255, 255, 255, 0.8);
    }
    
    &:nth-child(3) {
      background-color: rgba(255, 255, 255, 1);
    }
  }
}

// 响应式设计
@media (max-width: 375px) {
  .user-card {
    padding: 30rpx 25rpx;
  }
  
  .avatar {
    width: 80rpx !important;
    height: 80rpx !important;
  }
  
  .avatar-border {
    width: 96rpx !important;
    height: 96rpx !important;
  }
  
  .nickname {
    font-size: 28rpx !important;
  }
  
  .register-time {
    font-size: 22rpx !important;
  }
}
</style>